#!/usr/local/bin/python
#-*- encoding:utf-8 -*- 
import codecs 
from whoosh.index import create_in  
from whoosh.fields import *  
from whoosh import qparser
import ConfigParser

from whoosh.index import open_dir

import utils 
config = utils.get_config();

dictionary = open(config.get('rmls', 'dictionary'), 'r');

dict = {}
dx = 22889
index = 0;
for line in dictionary:
    if line.strip() != '':
        word = line.split('\t')[0];
        dict[index] = word;
        index += 1;

print len(dict);

Lx = utils.load_sparse_csr('Lx_sys_1_five.txt.npz');

Ly = utils.load_sparse_csr('Ly_sys_1_five.txt.npz');

M = Lx.dot(Ly.transpose());
M.eliminate_zeros();
for i in range(dx):
    s = '%s\t' % dict[i];
    row = M.getrow(i);
    if len(row.indices)  == 0:
        continue;
    for j in range(len(row.indices)):
        if row.data[j] > 0.001:
            s = '%s %s:%f' % (s, dict[row.indices[j]], row.data[j]); 
    print s;
